package Service.Impl;

import Dao.PromotionAdMapper;
import Dao.PromotionSpaceMapper;
import Service.PromotionAdService;
import Service.PromotionSpaceService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import domain.PromotionAd;
import domain.PromotionAdVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class PromotionAdServiceImpl implements PromotionAdService {

    @Autowired
    private PromotionAdMapper promotionAdMapper;


    /*
         分页查询 广告信息
     */
    @Override
    public PageInfo<PromotionAd> findPromotionAdByPage(PromotionAdVO promotionAdVO) {

        PageHelper.startPage(promotionAdVO.getCurrentPage(),promotionAdVO.getPageSize());
        List<PromotionAd> list = promotionAdMapper.findPromotionAdByPage();

        PageInfo<PromotionAd> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }

    /*
         动态更改 广告上下线状态
          前端传来的参数 为 id 和 status
     */

    @Override
    public void updatePromotionAdStatus(int id, int status) {

        //1. 封装数据
        PromotionAd promotionAd = new PromotionAd();
        promotionAd.setId(id);
        promotionAd.setStatus(status);
        promotionAd.setUpdateTime(new Date());

        //2. 调用Mapper
        promotionAdMapper.updatePromotionAdStatus(promotionAd);
    }
}
